package com.action.hurt
{
	import com.action.ActionHurt;
	import com.action.ActionStand;
	import com.resource.unit.ActionUnit;
	import com.stage.item.Player;
	
	public class ActionHurtNormal extends ActionHurt
	{
		/**
		 * 打得跳起来
		 * 被打得离开地面一定距离，并且往相反方向退一定距离
		 * 动作流程：目标角色做受伤动作（击飞或击退），动作结束并着地做着地动作（到地或直接跳过），做复原动作（站立或死亡或眩晕等状态动作）
		 */
		protected var _upSpeed:Number = -10; // 击飞初始速度
		protected var _isOnLand:Boolean = false;
		
		public function ActionHurtNormal(player:Player, data:Object)
		{
			super(player, data);
			_speed = -2;
		}
		
		public override function start(dir:int=1, moveDir:int=0):void{
			_player.view.isStop = false;
			_actFinish = false;
			
			// TODO 根据技能，设置击退和击飞效果
			_player.act = ActionUnit.HURT; // 受伤动作应该也有不同
			_upSpeed = -15;
			_speed = -2;
			
			super.start(dir);
			_downSpeed = _upSpeed;
		}
		
		protected override function enterFrame():void{
			if(!_isOnLand){
				checkGround();
				_player.x -= _speed * _dir;
			}
		}
		
		protected override function onLandGround():void{
			if(_isOnLand){
				return;
			}
			// TODO 根据技能决定下一步角色动作
			if(true){
				_isOnLand = true;
				_player.view.isStop = false;
				_player.act = ActionUnit.DIE;
				_player.addActionEndListener(landGroundEnd);
			}else{
				landGroundEnd(_player);
			}
		}
		
		protected function landGroundEnd(player:Player):void{
			_player.removeActionEndListener(landGroundEnd);
			if(true){
				actionCallback();
			}else{
				// 击晕，或者死亡等等动作	
			}
		}
		
		protected override function actionEnd(player:Player):void{
			// 做完完整动作，在检查是否着地中统一处理后续动作
			_player.removeActionEndListener(actionEnd);
			_player.view.isStop = true;
			_actFinish = true;
		}
		
		public override function end():void{
			_player.view.isStop = false;
			super.end();
		}
	}
}